﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuDada.Core.Post;
using WuDada.Core.Post.Service;
using WuDada.Core.Post.Domain;

public partial class learning2_in : System.Web.UI.Page
{
    private PostFactory m_PostFactory;
    private IPostService m_PostService;
    private SessionHelper m_SessionHelper;
    private int m_PostId = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        m_PostFactory = new PostFactory();
        m_PostService = m_PostFactory.GetPostService();
        m_SessionHelper = new SessionHelper();
        m_PostId = QueryStringHelper.GetInteger("post", 0);

        if (m_SessionHelper.Member == null)
        {
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJSAndRedirect("請先登入會員。", "login.aspx"), false);
            return;
        }

        if (!IsPostBack)
        {
            PostVO postVO = m_PostService.GetPostByIdNoLazy(m_PostId);
            if (postVO != null)
            {
                ltlTitle.Text = postVO.Title;
                hdnId.Value = postVO.PostId.ToString();
                if (!string.IsNullOrEmpty(postVO.DocFileName))
                {
                    string strVideo = "<object id='presentation' width='581' height='353' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' align='middle'>";
                    strVideo += "<param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='upload/{0}' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><param name='allowFullScreen' value='true' />";
                    strVideo += "<embed src='upload/{0}' width='581' height='353' quality='high' bgcolor='#ffffff' name='presentation' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' allowFullScreen='true'></embed></object>";
                    ltlVideo.Text = string.Format(strVideo, postVO.DocFileName);
                    
                }
                else
                {
                    ltlVideo.Text = "尚未提供講義課程";
                }

                linkDownFile.NavigateUrl = string.Format("learning_in.aspx?post={0}", postVO.PostId);
            }
            else
            {
                Response.Redirect("learning.aspx");
            }
        }
    }

    protected void btnTest_Click(object sender, EventArgs e)
    {
        Response.Redirect(string.Format("learning_test.aspx?post={0}", hdnId.Value));
    }
}